﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.ComponentModel.Composition;
using BackupAssurance.Library.Interfaces;
using System.Diagnostics;


namespace BackupAssurance.expLogging
{

    [Export(typeof(IfLogger)), PartCreationPolicy(CreationPolicy.Shared)]
    public class expLog : IfLogger
    {
        static TraceSource objTraceInfo;
        static TraceSource objTraceError;

        public expLog()
        {
            objTraceInfo = new TraceSource("BackupAssuranceInfo");
            objTraceError = new TraceSource("BackupAssuranceError");
            //objTraceInfo.Switch.Level = SourceLevels.All;
        }

        public void FlushInfo()
        {
            objTraceInfo.Flush();
            objTraceInfo.Close();

        }
        public void FlushError()
        {
            objTraceError.Flush();
        }

        //----------------------------------------------------------------------------------
        public void WriteLine(string strText)
        {
            logInfo(TraceEventType.Information, 0, strText);
        }

        public void WriteInfo(int errorcode, string strText)
        {
            logInfo(TraceEventType.Information, errorcode, strText);
        }

        private void logInfo(TraceEventType texttype, int errorcode, string strText)
        {
            objTraceInfo.TraceEvent(texttype, errorcode, strText);
        }

        //----------------------------------------------------------------------------------

        public void WriteWarn(int errorcode, string strText)
        {
            logError(TraceEventType.Warning, errorcode, strText);
        }

        public void WriteError(int errorcode, string strText)
        {
            logError(TraceEventType.Error, errorcode, strText);
        }

        private void logError(TraceEventType texttype, int errorcode, string strText)
        {
            objTraceError.TraceEvent(texttype, errorcode, strText);
        }

    }
}
